package com.kuang.demo02;

import java.util.ArrayList;
import java.util.List;

/**体会线程不安全的集合效果
 * @author FHL
 */
public class UnsafeList {
    public static synchronized void main(String[] args) {
        List<String> list=new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                synchronized (list){
                    list.add(Thread.currentThread().getName());
                }

            }).start();
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(list.size());
    }


}
